package com.wunu.controller;


import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.wunu.annotation.Log;
import com.wunu.annotation.Pass;
import com.wunu.annotation.ValidationParam;
import com.wunu.config.ResponseHelper;
import com.wunu.config.ResponseModel;
import com.wunu.entity.Menu;
import com.wunu.entity.Role;
import com.wunu.entity.User;
import com.wunu.model.RoleToMenuModel;
import com.wunu.service.IRoleService;
import com.wunu.service.IRoleToMenuService;
import com.wunu.service.IUserService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wunu kin
 * @since 2019-03-25
 */
@CrossOrigin
@RestController
@RequestMapping("/roleToPermission")
//不加入swagger ui里
public class RoleToMenuController {
	
    @Autowired
    private IRoleService roleService;
    
    @Autowired
    IRoleToMenuService roleToMenuService;
    /**
          *  菜单操作权限列表
	 */
    @ApiOperation(value="用户菜单权限操作列表", notes="hander参数,需要Authorization,roleCode从登录用户信息中获取",produces = "application/json")
    @ApiImplicitParams({
    				@ApiImplicitParam(name = "pageIndex", value = "第几页", dataType = "String",paramType="query"),
    				@ApiImplicitParam(name = "pageSize", value = "每页多少条", dataType = "String",paramType="query"),
    				@ApiImplicitParam(name = "roleCode", value = "role-cf8fea2055344df59a0d3e80540c78f9" , dataType = "String",paramType="query")   	
      				})
	@GetMapping("/pageList")
	public ResponseModel<Page<RoleToMenuModel>> getPageList(@RequestParam(name = "pageIndex", defaultValue = "1", required = false) Integer pageIndex,
                                @RequestParam(name = "pageSize", defaultValue = "10", required = false)  Integer pageSize,
                                @RequestParam(name = "roleCode" , required = false) String roleCode){
   //根据姓名查分页
	 Page<RoleToMenuModel> roleMenPage = roleToMenuService.selectPermissionPage(new Page<RoleToMenuModel>(pageIndex, pageSize),roleCode);
	 return ResponseHelper.buildResponseModel(roleMenPage);
	}

	@GetMapping("/permission")
	@Log(action="findPermissionByCode",modelName= "permission",description="查询菜单权限接口")
	public ResponseModel<RoleToMenuModel> findPermissionByCode(
			 @RequestParam(name = "roleCode") String roleCode,
			 @RequestParam(name = "menuCode") String menuCode) throws Exception{
	    return ResponseHelper.buildResponseModel( roleToMenuService.findPermissionByCode(roleCode,menuCode));
	}
}

